package fun.stgoder.dev.listener.sdk;

import fun.stgoder.dev.listener.common.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.*;

public class FaceMsgExecutor {
    private static final Logger logger = LoggerFactory.getLogger(FaceMsgExecutor.class);
    private static final ExecutorService executor;

    static {
        int processors = Runtime.getRuntime().availableProcessors();
        executor = new ThreadPoolExecutor(processors * 2, // core size
                processors * 2 * 2, 60L, TimeUnit.SECONDS, // maximum size
                new LinkedBlockingQueue<Runnable>(512), // task queue size
                Executors.defaultThreadFactory(), // thread factory
                (r, executor) -> { // abort
                    if (Constants.TEST_MODE)
                        logger.info("discard");
                });
    }

    public static void execute(FaceMsgTask task) {
        executor.execute(task);
    }
}
